import gradio as gr
import requests

# 替换为你的DeepSeek API密钥
DEEPSEEK_API_KEY = "sk-69cd183139d8439daa7fabc2a94498bd"
DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions"  # 假设这是DeepSeek的API地址


def ask_deepseek(question):
    headers = {
        "Authorization": f"Bearer {DEEPSEEK_API_KEY}",
        "Content-Type": "application/json"
    }

    data = {
        "model": "deepseek-chat",  # 假设这是DeepSeek的模型名称
        "messages": [{"role": "user", "content": question}]
    }

    response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data)

    if response.status_code == 200:
        result = response.json()
        return result['choices'][0]['message']['content']
    else:
        return f"Error: {response.status_code}, {response.text}"


# 创建Gradio界面
iface = gr.Interface(
    fn=ask_deepseek,  # 调用DeepSeek API的函数
    inputs="text",  # 输入框，用户输入问题
    outputs="text",  # 输出框，显示DeepSeek的回答
    title="DeepSeek 问答系统",
    description="输入你的问题，DeepSeek 将为你提供答案。"
)

# 启动Gradio应用
iface.launch()